package com.wbw.controller;

import com.rabbitmq.client.impl.Environment;
import com.wbw.service.userregisterservice.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.InputStream;


@RestController
@RequestMapping("/demo")
public class UserRegisterController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private UserService userService;

    private static String name;

    @Value("${my.name}")
    public void setName(String name) {
        this.name = name;
    }

//    @PostConstruct
//    public void test(String name) {
//        this.name = name;
//    }

    // 0/2 * * * * ?    每2秒执行一次
    // 0 0 0/2 * * ?    每2小时执行一次

    //@Scheduled(cron = "0/2 * * * * ?")
    public static void test() {
        System.out.println(name);

    }

    @GetMapping("/register")
    public String register(String username) {

        //userService.register(username);
        try {
//            String s = this.getClass().getClassLoader().getResource("").getPath(); // /D:/IdeaProjects/test/target/classes/com/wbw/controller/
//            String s1 = this.getClass().getClassLoader().getResource("/").getPath(); //  /D:/IdeaProjects/test/target/classes/
//            String s2 = this.getClass().getClassLoader().getResource("").getPath(); // /D:/IdeaProjects/test/target/classes/
//            String s3 = ClassLoader.getSystemResource("").getPath(); // /D:/IdeaProjects/test/target/classes/
//            InputStream is = this.getClass().getResourceAsStream("/application.yml"); //获取classes下的name.txt
            String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();

            logger.info("s1===============" + path);
        } catch (Exception e) {
            logger.info("===============异常" + e);
        }
        return "success";
    }

}